#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int* masterMind(char* solution, char* guess, int* returnSize)
{
    int tmp[26] = { 0 };
    int tmp1[26] = { 0 };
    int right = 0;
    int non_right = 0;
    int* ans = (int*)malloc(2 * sizeof(int));
    *returnSize = 2;
    for (int i = 0 ; i<4; ++i)
    {
        if (guess[i] == solution[i])
            right++;
        else
        {
            ++tmp[solution[i] - 'A'];
            ++tmp1[guess[i] - 'A'];
        }        
    }
    non_right += fmin(tmp['R' - 'A'], tmp1['R' - 'A']);
    non_right += fmin(tmp['G' - 'A'], tmp1['G' - 'A']);
    non_right += fmin(tmp['B' - 'A'], tmp1['B' - 'A']);
    non_right += fmin(tmp['Y' - 'A'], tmp1['Y' - 'A']);
    ans[0] = right;
    ans[1] = non_right;
    return ans;
}

int cmp(const void* a, const void* b)
{
    return *(int*)a - *(int*)b;
}

int* twoSum(int* numbers, int numbersLen, int target, int* returnSize) 
{
    qsort(numbers, numbersLen, sizeof(int), cmp);
    int left = 0;
    int right = numbersLen - 1;
    int* ans = (int*)malloc(3 * sizeof(int));
    while (left < right)
    {
        if (numbers[left] + numbers[right] < target)
            ++left;
        else if (numbers[left] + numbers[right] > target)
            --right;
        else
        {
            ans[1] = left;
            ans[2] = right;
            return ans;
        }
    }
}